<?php
namespace app\sisome\controller;

use think\Controller;
use think\Db;
use think\Cache;

class Setting extends Controller
{
    //服务器定时任务
    public function _empty($name)
    {
        die('非法访问！你的IP已被监控！');
    }

    /**
     * @name 添加ip
     * @return \think\response\View
     */
    public function add_ip(){
        if (!$_POST) {
            $allow_ip = setting('allow_ip');
            $setting['allow_ip'] = $allow_ip;
            $this->assign('setting',$setting);
            return view();
        } else {
            // dump($_POST);die();
            unset($_POST['__token__']);
            $num = 0;
            foreach ($_POST as $key => $val) {
                if (is_array($val)) {
                    $val = json_encode($val);
                }
                $ret = db('setting')->where('key', $key)->setField('val', $val);
                $num = $ret ? $num + 1 : $num;
            }
            $this->success('成功更新了 ' . $num . ' 项！');
        }
    }



}
